package cn.kxhp.mybatis3.dao.mapper.ext;


import cn.kxhp.mybatis3.dao.sql.UserSqlProvider;
import cn.kxhp.mybatis3.entity.User;
import cn.kxhp.mybatis3.pojo.UserRoleDTO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author Lianxw
 * @since 2022/3/28
 */
@Mapper
public interface UserExtMapper {


    /**
     * 用户关联角色查询
     * @param condition 查询条件
     */
    @SelectProvider(type = UserSqlProvider.class, method = "selectUserWithRole")
    @Results(id = "userWithRoleResultMap", value = {
            @Result(column = "u_id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "u_uid", property = "uid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "u_username", property = "username", jdbcType = JdbcType.VARCHAR),
            @Result(column = "u_phone", property = "phone"),
            @Result(column = "u_status", property = "status"),
            @Result(property = "roles", javaType = List.class, many = @Many(columnPrefix = "r_",
                    resultMap = "cn.kxhp.mybatis3.dao.mapper.base.RoleMapper.roleBaseResultMap")
            )
    })
    List<UserRoleDTO> selectUserWithRole(@Param("condition")final User condition);
}
